import { usePermissionStoreWithOut } from '../store/modules/permission';
import { router } from '../router/index';

export function hashPowerList(powerList: string[]): Recordable {
  const _obj: Recordable = {};
  for (const power of powerList) {
    _obj[power] = true;
  }
  return _obj;
}

export function checkPower(hashPower: Recordable, powerName: string): boolean {
  return !!hashPower[powerName];
}

export function checkPowerByName(elementName: string) {
  const permissionStore = usePermissionStoreWithOut();
  const path = router.currentRoute.value.path.replace(/\//g, ':').slice(1);
  const hashPower = permissionStore.getHashPower;
  const powerName = `${path}:${elementName}`;
  return !!hashPower[powerName];
}

export function getCurrentPath(): string {
  return router.currentRoute.value.path;
}
